﻿#include "CFDPostOperatorsDelete.h"

#include "PostGraphAdaptor/PostGraphObjectManager.h"
#include "PostGraphAdaptor/PostGraphObjectBase.h"
#include "PostGraphAdaptor/PostGraphObjectAgent.h"

#include "CFDPost/CFDPostOperatorsGUI/CFDPostOperModelTreeMouseEvent.h"
#include "CFDPost/CFDPostOperatorsInterface/CFDPostGraphEventOperator.h"

#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Interface/FITKInterfaceCFDPost/FITKAbstractCFDPostData.h"
#include "FITK_Interface/FITKInterfaceCFDPost/FITKCFDPost3DManager.h"
#include "FITK_Interface/FITKInterfaceCFDPost/FITKCFDPostData.h"

namespace OperModel
{
    CFDPostOperatorsDelete::CFDPostOperatorsDelete()
    {

    }

    bool CFDPostOperatorsDelete::execGUI()
    {
        int objID = -1;
        argValue(objID_String, objID);
        if (objID <= 0)return false;
        Interface::FITKCFDPost3DManager* dataManager = FITKAPP->getGlobalData()->getPostData<Interface::FITKCFDPostData>()->getPostDataManager();
        if (dataManager == nullptr)return false;
        Interface::PostGraphObjectManager* actorManager = Interface::PostGraphObjectManager::getInstance();
        if (actorManager == nullptr)return false;

        //删除渲染数据
        int actorID = -1;
        for (int i = 0; i < actorManager->getDataCount(); i++)
        {
            Interface::PostGraphObjectAgent* agent = actorManager->getDataByIndex(i);
            if (agent == nullptr)continue;
            Interface::PostGraphObjectBase* graphObj = agent->getGraphObject();
            if (graphObj == nullptr)continue;
            if (graphObj->getPostID() == objID) {
                actorID = agent->getDataObjectID();
                break;
            }
        }
        actorManager->removeDataByID(actorID);

        //删除vtk数据
        dataManager->removeDataByID(objID);
        return true;
    }

    bool CFDPostOperatorsDelete::execProfession()
    {
        //更新渲染窗口
        EventOper::CFDPostGraphEventOperator* graphOper =
            FITKOPERREPO->getOperatorT<EventOper::CFDPostGraphEventOperator>("OperGraphPreprocess");//获取OperGraphPreprocess实例

        if (graphOper == nullptr)
        {
            return false;
        }
        graphOper->reRender();

        // 获取文件树的相关数据
        GUIOper::CFDPostOperModelTreeMouseEvent* treeOper =
            FITKOPERREPO->getOperatorT<GUIOper::CFDPostOperModelTreeMouseEvent>("CFDPostModelTreeEvent");//获取ModelTreeEvent实例？

        if (treeOper == nullptr)
        {
            return false;
        }
        treeOper->updateTree();


        //更新界面
        EventOper::ParaWidgetInterfaceOperator* infoOper = FITKOPERREPO->getOperatorT<EventOper::ParaWidgetInterfaceOperator>("OperatorsWidget");
        if (infoOper)
        {
            infoOper->CurrentObjectChange(-1);
        }
        return true;
    }
}
